package com.ohuang.wallpapermanager

import com.ohuang.wallpapermanager.data.TimeData
import com.ohuang.wallpapermanager.data.TimeFrameData
import com.ohuang.wallpapermanager.util.TimeUtil
import com.ohuang.wallpapermanager.wallpaper.isMatch
import org.junit.Test

import org.junit.Assert.*

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {
    @Test
    fun addition_isCorrect() {
        assertEquals(4, 2 + 2)
    }

    @Test
    fun `获取星期几`() {
        var week = TimeUtil.getWeek(1717471940000) //星期二
        assertEquals(2, week)
        week = TimeUtil.getWeek(1717299140000) //星期日
        assertEquals(0, week)
    }


    @Test
    fun `获取小时`() {
        var hour = TimeUtil.getHour(1717577760000)
        assertEquals(16, hour)
        hour = TimeUtil.getHour(17176032000000)
        assertEquals(0, hour)
    }

    @Test
    fun `获取分钟`() {
        var minute = TimeUtil.getMinute(1717606740000)
        assertEquals(59, minute)
        minute = TimeUtil.getMinute(1717603200000)
        assertEquals(0, minute)
    }

    @Test
    fun `是否在时间段之内`() {

        val match = TimeFrameData(
            startTime = TimeData(hour = 10, minute = 30),
            endTime = TimeData(hour = 20, minute = 45)
        ).isMatch(TimeData(hour = 20, minute = 45))
        assertEquals(true, match)  //刚好在范围内
        val match1 = TimeFrameData(
            startTime = TimeData(hour = 0, minute = 0),
            endTime = TimeData(hour = 0, minute = 0)
        ).isMatch(TimeData(hour = 20, minute = 45))
        assertEquals(true, match1) // starTime == endTime 代表全时间段


        val match2 = TimeFrameData(
            startTime = TimeData(hour = 0, minute = 0),
            endTime = TimeData(hour = 10, minute = 0)
        ).isMatch(TimeData(hour = 20, minute = 45))
        assertEquals(false, match2)  //不在范围内
        val match3 = TimeFrameData(
            startTime = TimeData(hour = 10, minute = 0),
            endTime = TimeData(hour = 9, minute = 0)
        ).isMatch(TimeData(hour = 20, minute = 45))
        assertEquals(true, match3)    //start > end  代表跨天
        val match4 = TimeFrameData(
            startTime = TimeData(hour = 10, minute = 0),
            endTime = TimeData(hour = 9, minute = 0)
        ).isMatch(TimeData(hour = 9, minute = 30))
        assertEquals(false, match4)    //start > end  代表跨天
        val match5 = TimeFrameData(
            startTime = TimeData(hour = 9, minute = 0),
            endTime = TimeData(hour = 10, minute = 0)
        ).isMatch(TimeData(hour = 9, minute = 30))
        assertEquals(true, match5)

        val match6 = TimeFrameData(
            startTime = TimeData(hour = 9, minute = 30),
            endTime = TimeData(hour = 10, minute = 0)
        ).isMatch(TimeData(hour = 9, minute = 30))
        assertEquals(true, match6)
        val match7 = TimeFrameData(
            startTime = TimeData(hour = 9, minute = 30),
            endTime = TimeData(hour = 10, minute = 0)
        ).isMatch(TimeData(hour = 10, minute = 30))
        assertEquals(false, match7)
        val match8 = TimeFrameData(
            startTime = TimeData(hour = 9, minute = 30),
            endTime = TimeData(hour = 10, minute = 0)
        ).isMatch(TimeData(hour = 10, minute = 50))
        assertEquals(false, match8)
        val match9 = TimeFrameData(
            startTime = TimeData(hour = 9, minute = 30),
            endTime = TimeData(hour = 10, minute = 0)
        ).isMatch(TimeData(hour = 10, minute = 50))
        assertEquals(false, match9)
        val match10 = TimeFrameData(
            startTime = TimeData(hour = 10, minute = 30),
            endTime = TimeData(hour = 10, minute = 0)
        ).isMatch(TimeData(hour = 10, minute = 20))
        assertEquals(false, match10)
        val match11 = TimeFrameData(
            startTime = TimeData(hour = 10, minute = 0),
            endTime = TimeData(hour = 10, minute = 0)
        ).isMatch(TimeData(hour = 20, minute = 45))
        assertEquals(true, match11) // starTime == endTime 代表全时间段

        val match12 = TimeFrameData(
            startTime = TimeData(hour = 11, minute = 0),
            endTime = TimeData(hour = 14, minute = 0)
        ).isMatch(TimeData(hour = 11, minute = 16))
        assertEquals(true, match12) // starTime == endTime 代表全时间段
    }
}